<template>
  <div>
    <FilterTable
      ref="table"
      columnsRef="fyhRepairStuff"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :columns="columns"
      :datakey="'rows'"
      :height="'auto'"
      :onColumnsChange="columns => (this.columns = columns)"
    >
      <template slot="controls">
        <!-- <el-button type="primary" @click="openReception">前台领料</el-button> -->
      </template>
    </FilterTable>
    <!-- 前台领料 -->
    <!-- <BaseDialog :visible.sync="showReception" title="前台领料" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Reception :roNo="roNo" :tax="tax" :isShow="false" @cancel="showReception = false"></Reception>
    </BaseDialog> -->
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { all } from 'q';
import { queryUnitCode } from '@/api/part/partInfo';
import { getChexSelectTable } from '@/api/repair/repairReception/customer/brand.js';
import { queryRepairLabour, querySellMaterial, queryChargeDifferentiationList } from '@/api/repair/repairReception/repairBusinessManger';
import { getSeries } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { getpartByestimateNOList } from '@/api/repair/repairReception/evaluation/index';
// import { getSystemDefault } from '@/api/repair/repairReception/customer';
// import Reception from '@/pages/part/partOutbound/repairMaterials/components/reception';
import { getAllUser } from '@/api/customerRepair/activityVisit/resultEntry'; // 查询所有用户
import { queryTax } from '@/api/part/partOutbound/repairMaterials/index.js';
import moment from 'moment';
export default {
  name: 'RepairProsss',
  components: {
    // Reception
  },
  mixins: [dictionary],
  props: ['dataList', 'ESTIMATE_NO'],
  data() {
    return {
      columns: this.createTable(),
      list: [],
      fetchApi: getpartByestimateNOList,
      fetchParams: {},
      showReception: false,
      // tax: 0,
      orderStatus: '' // EP判断一车一单
    };
  },
  created() {
    let roNo = this.ESTIMATE_NO;
    this.fetchParams = Object.assign({}, { code: roNo }, { xhrAbort: false });
    // this.getAllUser();
  },
  mounted() {
    // this.queryRepairMaterial(); // 维修材料查询
    this.queryChargeList();
    this.querySeries();
    // this.getSystemDefault();
    // this.getAllUser();
    // this.queryTax();
    // this.getUnitCode();
  },
  methods: {
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '是否入账',
          dataIndex: 'IS_FINISHED',
          sorter: true,
          // filter: true,
          render: props => {
            return <span>{props.row.IS_FINISHED}</span>;
          }
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          // filter: true,
          // filterType: 'checkbox',
          editable: false,
          editItems: [],
          defaultEditable: false,
          editType: 'select'
        },
        {
          title: '备件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          showOverflowTooltip: true
          // filter: true
        },
        {
          title: '备件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          // filter: true,
          editable: false,
          editType: 'text',
          defaultEditable: false,
          showOverflowTooltip: true
        },
        {
          title: '备件销售单价',
          dataIndex: 'PART_SALES_PRICE',
          sorter: true,
          // filter: true,
          initialValue: '0',
          editable: false,
          editType: 'number',
          defaultEditable: false,
          precision: 2
        },
        // {
        //   title: '成本价',
        //   dataIndex: 'COST_PRICE',
        //   summationPrecision: 2,
        //   sorter: true,
        //   filter: true
        // },
        {
          title: '维修项目名称',
          dataIndex: 'LABOUR_CODE',
          sorter: true,
          // filter: true,
          editable: false,
          editType: 'select',
          defaultEditable: false,
          showOverflowTooltip: true,
          editItems: []
        },
        {
          title: '备件销售金额',
          dataIndex: 'PART_SALES_AMOUNT',
          sorter: true,
          // filter: true,
          precision: 2
        },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          // filter: true,
          precision: 2
        },
        {
          title: '主要备件',
          dataIndex: 'IS_MAIN_PART',
          sorter: true,
          editable: false,
          defaultEditable: false,
          editType: 'checkbox',
          editItems: [
            { text: '', trueValue: '10041001' },
            { text: '', falseValue: '10041002' }
          ]
        },
        {
          title: '备件数量',
          dataIndex: 'PART_QUANTITY',
          sorter: true,
          // filter: true,
          editable: false,
          defaultEditable: false,
          editType: 'number',
          precision: 0
        },
        // {
        //   title: '计量单位',
        //   dataIndex: 'UNIT_NAME',
        //   sorter: true,
        //   filter: true,
        // },
        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          sorter: true,
          // filter: true,
          precision: 2
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true,
          // filter: true,
          // disabled: true,
          editable: false,
          editType: 'number',
          precision: 2
        },
        {
          title: '仓库代码',
          dataIndex: 'STORAGE_CODE',
          sorter: true
          // filter: true
        },
        {
          title: '不可打折',
          dataIndex: 'IS_DISCOUNT',
          sorter: true,
          // filter: true,
          disabled: true,
          render: (props, h) => {
            let val = this.createDictText(props.row.IS_DISCOUNT, '1278') === '1' ? true : false;
            return <el-checkbox value={val} onInput={e => (val === e ? '1' : '0')}></el-checkbox>;
          }
        },
        {
          title: '是否增项',
          dataIndex: 'IS_ADDITION',
          sorter: true,
          // filter: true,
          render: props => {
            return <span>{this.createDictText(props.row.IS_ADDITION, '1278')}</span>;
          }
        },
        {
          title: '库位代码',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true
          // filter: true
        },
        {
          title: '是否内返',
          dataIndex: 'INTER_RETURN',
          sorter: true,
          // filter: true,
          editable: false,
          render: (props, h) => {
            let val = props.row.INTER_RETURN === '1' ? true : false;
            return <el-checkbox value={val} onInput={e => (props.row.INTER_RETURN = e ? '1' : '0')}></el-checkbox>;
          }
        },
        {
          title: '故障部位',
          dataIndex: 'POS_NAME',
          sorter: true
          // filter: true
        }
      ];
    },
    // 所有用户
    async getAllUser() {
      const res = await getAllUser();
      // console.log('所有用户', res);
      // this.columns.find(item => item.dataIndex === 'SENDER').editItems = res.data.map(x => ({ value: x.userId + '', text: x.employeeName }));
      // this.columns.find(item => item.dataIndex === 'RECEIVER').editItems = res.data.map(x => ({ value: x.userId + '', text: x.employeeName }));
    },
    // async getUnitCode() {
    //   const res3 = await queryUnitCode();
    //   this.formList.find(item => item.dataIndex == 'UNIT_CODE').editItems = res3.data.map(x => ({ text: x.UNIT_NAME, value: x.UNIT_CODE }));
    // },
    // async getSystemDefault() {
    //   this.orderStatus = (await getSystemDefault({ itemCode: 8033 })).data;
    //   // EP判断一车一单
    //   if (this.orderStatus == '10041001') {
    //     this.columns.find(x => x.dataIndex === 'PART_NAME1').hidden = false; // 显示备件别名
    //   }
    // },
    createBaseTable() {
      this.BaseTable = this.$refs.table.$refs.pageTable;
    },
    openReception() {
      this.showReception = true;
    },
    daList(list) {
      this.list = list;
    },

    // 查询所有车系(供table使用)
    async querySeries() {
      const res = await getChexSelectTable();
      this.columns.find(x => x.dataIndex === 'MODEL_LABOUR_CODE').editItems = res.data.map(x => ({ value: x.seriesId + '', text: x.seriesName }));
    },

    // 查询收费区分
    async queryChargeList() {
      const res = await queryChargeDifferentiationList();
      // console.log(res, 'res');
      this.columns.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').editItems = res.data.map(x => ({
        value: x.CHARGE_PARTITION_CODE + '',
        text: x.CHARGE_PARTITION_NAME
      }));
    }

    // 请求税率
    // async queryTax() {
    //   const res = await queryTax();
    //   if (res.resultCode == 200) {
    //     this.tax = res.data;
    //   }
    // }
    // // 维修材料查询
    // async queryRepairMaterial() {
    //   const roNo = this.roNo;
    //   const res = (await queryRepairPart(roNo)).data.rows;
    //   this.list = res;
    // }

    // 传给父组件
    // syncTableFun(val) {
    //   if (val && val.length > 0) {
    //     delete val.dataMark;
    //     this.$emit('syncTablelist', val);
    //   } else {
    //     this.$emit('syncTablelist', []);
    //   }
    // }
  }
};
</script>

<style lang="less"></style>
